package com.cjy.cjy.tasks.executor.jobhandler;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.biz.model.TriggerParam;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

/**
 * 通过xxl-job启动datax中的任务
 *
 * @author cjy
 * @create 2020-04-21
 */

@JobHandler("executorDataXHandler")
@IocBean
public class ExecutorDataXHandler extends IJobHandler {
    @Inject
    protected PropertiesProxy conf;

    @Inject("java:$conf.check('datax.path')")
    private String datax_path;

    @Inject("java:$conf.check('datax.temp.josn.path')")
    private String datax_jsonpath;

    @Inject("java:$conf.check('datax.run.python.cmd')")
    private String datax_python;


    public ReturnT<String> execute(TriggerParam trigger) throws Exception {

        // java端执行python语句
        Process process = Runtime.getRuntime()
                .exec("python E:\\workspace_directory\\Datax-web\\target\\datax\\datax\\bin\\datax.py " +
                        "E:\\workspace_directory\\Datax-web\\target\\datax\\datax\\job\\mysql2mysql.json");

        process.waitFor();
        return ReturnT.SUCCESS;
    }

    @Override
    public ReturnT<String> execute(String trigger) throws Exception {
        return null;
    }
}
